package org.layuiframework.stereotype.vo;

import lombok.Data;

@Data
public class ResultVo{
    private int code;
    private String msg;
    private Object data;

    public ResultVo(int code, String msg,Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResultVo(Object data){
        this(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), data);
    }

    public ResultVo(StatusCode statusCode, Object data){
        this(statusCode.getCode(), statusCode.getMsg(), data);
    }

    public ResultVo(StatusCode statusCode){
        this(statusCode.getCode(), statusCode.getMsg(), null);
    }

    public static ResultVo ok (){
        return new ResultVo(ResultCode.SUCCESS);
    }

    public static ResultVo error (){
        return new ResultVo(ResultCode.FAILED);
    }

    public static ResultVo build (boolean flag){ return flag ? ok() : error();}
}
